﻿using SKeeper.Application.Services.Item;
using SKeeper.Persistence.Facade;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using SKeeper.Application.ViewModels.Items;

namespace SKeeper.Controllers
{
    [Authorize]
    public class ItemController : Controller
    {
        private DomainModelFacade db;
        private ItemControllerService service;

        public ItemController()
        {
            this.db = new DomainModelFacade();
            this.service = new ItemControllerService(this.db);
        }

        // GET: Item
        public ActionResult Index()
        {
            var userId = this.User.Identity.GetUserId();
            var model = this.service.GetIndexViewModel(userId);
            return View(model);
        }

        [HttpPost]
        public ActionResult Add(ItemViewModel model)
        {
            this.service.CreateItem(model);

            IEnumerable<ItemViewModel> items = this.service.GetAllItems(model.CompanyId);

            return this.PartialView("_ItemsPartial", items);
        }
    }
}